const mysql = require('mysql')
const config = require('../config/index')

module.exports = (sql, sqlParams = []) => {
  return new Promise((resolve, reject) => {
    const pool = mysql.createPool(config.db)
    pool.getConnection((error, conn) => {
      if (error) reject(error)
      conn.query(sql, sqlParams, (err, res) => {
        if (err) reject(err)
        resolve(res)
        conn.destroy()
      })
    })
  })
}